package com.xinqi.modules.sys.textbook.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.sys.textbook.dto.req.CloudTextbookCatalogQueryDTO;
import com.xinqi.modules.sys.textbook.dto.rsp.CloudTextbookCatalogResultDTO;
import com.xinqi.modules.sys.textbook.service.CloudTextbookCatalogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 云课本章节目录APP控制层
 *
 * @author: linkai
 * @date: 2023/04/25
 */
@Tag(name = "APP-云课本", description = "云课本App接口")
@RestController
@RequestMapping("/app/cloud-textbook")
@RequiredArgsConstructor
public class CloudTextbookCatalogAppController {
    private final CloudTextbookCatalogService cloudTextbookCatalogService;

    /**
     * 云课本章节目录-分页
     */
    @Operation(summary = "云课本章节目录-分页")
    @GetMapping("/{textbookId}/catalog/page")
    public R<PageInfo<CloudTextbookCatalogResultDTO>> page(@Parameter(description = "云课本ID", example = "100001") @PathVariable("textbookId") Long textbookId,
                                                           @ParameterObject CloudTextbookCatalogQueryDTO dto) {
        dto.setTextbookId(textbookId);
        PageInfo<CloudTextbookCatalogResultDTO> page = cloudTextbookCatalogService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 云课本章节目录-详情
     */
    @Operation(summary = "云课本章节目录-详情")
    @GetMapping("/{textbookId}/catalog/{id}")
    public R<CloudTextbookCatalogResultDTO> findById(@Parameter(description = "云课本ID", example = "100001") @PathVariable("textbookId") Long textbookId,
                                                     @Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        CloudTextbookCatalogResultDTO dto = cloudTextbookCatalogService.findById(id);
        return R.data(dto);
    }

    /**
     * 云课本章节目录-树
     */
    @Operation(summary = "云课本章节目录-树")
    @GetMapping("/{textbookId}/catalog/tree")
    public R<List<CloudTextbookCatalogResultDTO>> tree(@Parameter(description = "云课本ID", example = "100001") @PathVariable("textbookId") Long textbookId) {
        List<CloudTextbookCatalogResultDTO> list = cloudTextbookCatalogService.tree(textbookId);
        return R.data(list);
    }

}
